/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-07
 * Time: 15:23
 */
public class Demo19 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
            for (int i = 0; i < 3; i++) {
                System.out.println(Thread.currentThread().getName() + ": 我还在工作");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        //串行 -- 线程安全
        Thread t1 = new Thread(runnable,"张三");
        System.out.println("先让张三开始工作");
        t1.start();
        t1.join();
        Thread t2 = new Thread(runnable,"李四");
        System.out.println("张三工作完了，再让李四工作");
        t2.start();
        t2.join();
        System.out.println("李四工作完了");

        //并发执行 调度随机 --线程不安全
        /*Thread t1 = new Thread(runnable,"张三");
        System.out.println("先让张三开始工作");
        t1.start();
        Thread t2 = new Thread(runnable,"李四");
        System.out.println("张三工作完了，再让李四工作");
        t2.start();
        System.out.println("李四工作完了");*/

    }
}
